package com.river.controller;

import com.mysql.jdbc.Driver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by jl on 2018/9/4 0004
 */
@RestController
public class TestController {
    @Autowired
    HttpServletRequest httpServletRequest;

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test(@RequestParam String a, HttpServletRequest request) {
        System.out.println(request.getParameter("a"));
        System.out.println(httpServletRequest.getParameter("a"));
        System.out.println(httpServletRequest.getParameter("b"));
        return a;
    }

    @RequestMapping("/jdbc")
    public String testJdbc() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(Driver.class.getName());
        dataSource.setUrl("jdbc:mysql://localhost:3306/jyds");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");

        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSource);

        String sql = "select 1 from dual";
        Integer i = jdbcTemplate.queryForObject(sql, Integer.class);
        System.out.println(i);
        return i + "";
    }
}
